﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities;
using DAL;

namespace SurveyGUI
{
    public partial class AddInspectForm : Form
    {
        IInspectRepository rep = new InspectRepository();
        IAccountRepository repAccount = new AccountRepository();

        public AddInspectForm()
        {
            InitializeComponent();
        }

        //gan ten thanh tra sang form AddInspectAccount
        public string value 
        {
            get { return txtTen.Text; }   
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtTen.Text != "")
            {
                Inspect i = new Inspect();
                Account account = new Account();

                //add Inspect
                i.TenTT = txtTen.Text;
                string gt = "";
                if (RblNam.Checked)
                    gt = "Nam";
                else
                    gt = "Nữ";
                i.GioiTinh = gt;
                i.ChucVu = cbbChucVu.SelectedItem.ToString();
                i.TenDN = txtTenDN.Text;
                i.MatKhau = txtMK.Text;
                i.Ktra = 2;
                rep.Add(i);

                //add Account
                account.TenDN = txtTenDN.Text;
                account.MatKhau = txtMK.Text;
                account.Ktra = 2;
                repAccount.AddAccount(account);
                MessageBox.Show("Thêm thanh tra thành công");
                this.Close();
                //DialogResult dlg = MessageBox.Show("Thanh tra chưa có tài khoản, bạn phải tạo mới tài khoản cho thanh tra này!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //if (dlg == System.Windows.Forms.DialogResult.OK)
                //{
                //    AddInspectAccountForm account = new AddInspectAccountForm();
                //    //gan gia tri ten thanh tra cua form AddInspect sang form AddInspectAccount
                //    account.tenTT = txtTen.Text;
                //    account.ShowDialog();
                //    this.Close();
                //}
                //else
                //{
                //    rep.Delete(i);
                //}
            }
            else
                MessageBox.Show("Chưa nhập tên thanh tra");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoaTrang_Click(object sender, EventArgs e)
        {
            txtTen.Text = "";
            cbbChucVu.Text = cbKSV.Text;
            RblNam.Checked = true;
        }

        private void AddInspectForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOK.PerformClick();
            }
        }

        private void AddInspectForm_Load(object sender, EventArgs e)
        {
            this.AcceptButton = btnOK;
        }

    }
}
